/**
 * @file errormessages.h
 * @author Yao Zongyou <yaozy2010@gmail.com>
 * @date 2011-03-30
 */

#ifndef ERRORMESSAGES_H_2011_03_30
#define ERRORMESSAGES_H_2011_03_30

#pragma once

#ifdef __cplusplus
#define EXPORT extern "C" void WINAPI
#else
#define EXPORT void WINAPI
#endif

/**
 * @brief Calls GetLastError() and formats the result into a human readable
 * string which it then displays in a message box. The message box has the
 * MB_ICONINFORMATION style set
 */
EXPORT ErrorInfoA(void);
EXPORT ErrorInfoW(void);

/**
 * @brief Takes the input string and displays it in a message box with a caption of
 * "Application Error". The message box has the MB_ICONERROR style set
 * @param LPC(W)STR or string literal - The message to be displayed
 */
EXPORT ErrorMessageA(LPCSTR);
EXPORT ErrorMessageW(LPCWSTR);

/**
 * @brief The HRESULT equivalent of ErrorInfo(). Displays the textual equivalent of
 * a failed HRESULT in a message box. The message box has the MB_ICONERROR style set
 * @param HRESULT the value to be converted to its string equivalent
 * @note Some HRESULT's don't have an associated string and as such, this function
 * may show a blank message box. The return values from WSAGetLastError can be 
 * casted to HRESULT and passed into this function to get textual last error 
 * messages
 */
EXPORT HRErrorInfoA(HRESULT);
EXPORT HRErrorInfoW(HRESULT);

/**
 * @brief 
 * @param LPC(W)STR - A printf-style string with a maximum of 2 format specifiers 
 * (%s, %i, %x, etc)
 * @param LPVOID - The first argument to insert into the string
 * @param LPVOID - If only 1 format specifier is specified in the string then this 
 * parameter can be set to NULL, otherwise, it's the second argument in the string
 * @note After the arguments have been substituted into the string, only the first
 * 999 characters will appear in the message box. Anything bigger will be truncated
 * at 999.
 */
EXPORT DebugPrintA(LPCSTR, LPCVOID, LPCVOID);
EXPORT DebugPrintW(LPCWSTR, LPCVOID, LPCVOID);

#ifdef UNICODE
#define ErrorMessage ErrorMessageW
#define DebugPrint DebugPrintW
#define HRErrorInfo HRErrorInfoW
#define ErrorInfo ErrorInfoW
#else
#define ErrorMessage ErrorMessageA
#define DebugPrint DebugPrintA
#define HRErrorInfo HRErrorInfoA
#define ErrorInfo ErrorInfoA
#endif

#endif /* ERRORMESSAGES_H_2011_03_30 */
